package com.ruoyi.web.controller.voit;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.voit.domain.Maintenance;
import com.ruoyi.voit.service.IMaintenanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 充电桩维修记录Controller
 * 
 * @author ruoyi
 * @date 2025-07-17
 */
@RestController
@RequestMapping("/voit/maintenance")
public class MaintenanceController extends BaseController
{
    @Autowired
    private IMaintenanceService maintenanceService;

    /**
     * 查询充电桩维修记录列表
     */
    @PreAuthorize("@ss.hasPermi('voit:maintenance:list')")
    @GetMapping("/list")
    public TableDataInfo list(Maintenance maintenance)
    {
        startPage();
        List<Maintenance> list = maintenanceService.selectMaintenanceList(maintenance);
        return getDataTable(list);
    }

    /**
     * 导出充电桩维修记录列表
     */
    @PreAuthorize("@ss.hasPermi('voit:maintenance:export')")
    @Log(title = "充电桩维修记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Maintenance maintenance)
    {
        List<Maintenance> list = maintenanceService.selectMaintenanceList(maintenance);
        ExcelUtil<Maintenance> util = new ExcelUtil<Maintenance>(Maintenance.class);
        util.exportExcel(response, list, "充电桩维修记录数据");
    }

    /**
     * 获取充电桩维修记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('voit:maintenance:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") String recordId)
    {
        return success(maintenanceService.selectMaintenanceByRecordId(recordId));
    }

    /**
     * 新增充电桩维修记录
     */
    @PreAuthorize("@ss.hasPermi('voit:maintenance:add')")
    @Log(title = "充电桩维修记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Maintenance maintenance)
    {
        return toAjax(maintenanceService.insertMaintenance(maintenance));
    }

    /**
     * 修改充电桩维修记录
     */
    @PreAuthorize("@ss.hasPermi('voit:maintenance:edit')")
    @Log(title = "充电桩维修记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Maintenance maintenance)
    {
        return toAjax(maintenanceService.updateMaintenance(maintenance));
    }

    /**
     * 删除充电桩维修记录
     */
    @PreAuthorize("@ss.hasPermi('voit:maintenance:remove')")
    @Log(title = "充电桩维修记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable String[] recordIds)
    {
        return toAjax(maintenanceService.deleteMaintenanceByRecordIds(recordIds));
    }
}
